import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    address:[
      {
        'name':'张三',
        'tel':'12589666',
        'city':'北京市',
        'address':'昌平区',
        'flag':true
      },
    ]
  },
  mutations: {
    adduser(state,obj){
      state.address.push(obj)
    },
    del(state,index){
      state.address.splice(index,1)
    },
    //修改默认地址
    setflag(state,index){
      state.address.forEach(item => {
        item.flag = false
      })
      state.address[index].flag = true
    },
    //编辑地址
    editadress(state,obj){
      state.address[obj.index] = obj.info
    }
  },
  actions: {
  },
  modules: {
  },
  getters:{
    count(state){
      var num = state.address.length
      return num
    }
  }
})
